package lanQiaoBei.搜索与图论.dfs;

import java.io.*;

/*N皇后问题
* */
public class P3 {
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    final static int N=20;
    static int n;
    static boolean []col=new boolean[N],dj=new boolean[N],udj=new boolean[N];
    static char[][]g=new char[N][N];

    static void dfs(int d){
           if(d==n){
               for(int i=0;i<n;i++)
                   System.out.println(g[i]);
               System.out.println();
               return;
           }
           for(int i=0;i<n;i++){
               if(!col[i]&&!dj[d+i]&&!udj[i-d+n]){
                   g[d][i]='Q';
                   col[i]=dj[d+i]=udj[i-d+n]=true;
                   dfs(d+1);
                   g[d][i]='.';
                   col[i]=dj[d+i]=udj[i-d+n]=false;
               }
           }
    }
    public static void main(String[]args)throws Exception{
        n=Integer.parseInt(br.readLine());
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                g[i][j]='.';
        dfs(0);
    }
}
